//
//  ViewController.m
//  TBTest
//
//  Created by KOSUN on 2017/11/2.
//  Copyright © 2017年 KOSUN. All rights reserved.
//

#import "ViewController.h"
#import "TBModel.h"

@interface ViewController ()

@property (nonatomic, strong) TBModel *model;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ViewController



//实例化我们的Model
- (void)loadView{
    [super loadView];
    
    self.model = [[TBModel alloc] init];
    self.model.dataSource.tableCellIdentifier = NSStringFromClass([UITableViewCell class]);
    
    
    self.model.dataSource.tableCellConfigBlock = ^(UITableViewCell *targetCell, id data, NSInteger row) {
        //通过 block 直接给 cell 赋值
        targetCell.textLabel.text = data;
    };
    
    self.model.delegate.tableCellSelectBlock = ^(NSInteger row) {
        //通过 block 传递 cell 点击事件
        NSLog(@"点击 %ld",row);
    };
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _tableView = ({
        UITableView *view = [[UITableView alloc] initWithFrame:self.view.bounds];
        /*传递 UITableView 的 dataSource 和 delegate */
        view.dataSource = self.model.dataSource;
        view.delegate = self.model.delegate;
        [view registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
        view.rowHeight = 70;
        view;
    });
    [self.view addSubview:_tableView];
    
   
    
    /*给 Model 赋值*/
    self.model.listData = @[@"第0行",@"第1行",@"第2行",@"第3行",@"第4行",@"第5行",@"第6行"];
    
    [self.tableView reloadData];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
